/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =======================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =======================================================
 *   $Id: GameUI.java 667 2010-08-01 11:30:04Z Harry $
 *   $LastChangedDate: 2010-08-01 11:30:04 +0000 (Sun, 01 Aug 2010) $
 *   $LastChangedBy: Harry $
 *--------------------------------------------------------------------------
 */
package battlefield.ui;

import battlefield.resource.Graphics;
import battlefield.ui.screen.GameMenuScreen;
import battlefield.ui.screen.Screen;
import javax.swing.JFrame;

/**
 *
 * @author Yong Peng, Harry Nguyen
 */
public class GameUI extends JFrame {

    private Screen screen;

    /**
     * Constructs the GameUI object
     */
    public GameUI() {
        show(new GameMenuScreen());
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(970, 750);
        setLocationRelativeTo(null);
        setIconImage(Graphics.ICON_GAME.getImage());
        setTitle("Openfield");
        setResizable(false);
        setVisible(true);

    }

    /**
     * Replace the current screen with the one specify in the parameter
     * @param screen new screen to be used
     */
    public void show(Screen screen) {
        if (screen.equals(this.screen)) {
            return;
        }

        if (this.screen != null) {
            this.remove(this.screen);

        }

        this.screen = screen;
        this.add(this.screen);
        this.validate();
    }

    /**
     * Exit the application
     */
    public void exit() {
        System.exit(0);
    }


    /* Begin Region: State Pattern */
    /**
     * display Game Menu screen
     */
    public void home() {
        show(screen.home());
    }

    /**
     * Return to previous screen
     */
    public void back() {
        show(screen.back());
    }

    /**
     * Display the Game options screen
     */
    public void showOptions() {
        show(screen.showOptions());
    }

    /**
     * Display the Tutorials screen
     */
    public void showTutorials() {
        show(screen.showTutorials());
    }

    /**
     * Display the Credits screen
     */
    public void showCredits() {
        show(screen.showCredits());
    }

    /**
     * Save player's name and Display Game Menu screen
     */
    public void save() {
        show(screen.save());
    }

    /**
     * Display Game Creation screen
     */
    public void createNewGame() {
        show(screen.createNewGame());
    }

    /**
     * Display Join Game Screen
     */
    public void joinNetworkGame() {
        show(screen.joinNetworkGame());
    }

    /**
     * Display Map chooser screen
     */
    public void chooseMap() {
        show(screen.chooseMap());
    }

    /**
     * Display wait for player screen
     */
    public void waitForPlayers() {
        show(screen.waitForPlayers());
    }

    /**
     * Display tactical phase screen
     */
    public void startTactics() {
        show(screen.startTactics());
    }

    /**
     * Display war phase screen
     */
    public void startWar() {
        show(screen.startWar());
    }

    /**
     * Display Win screen
     */
    public void win() {
        show(screen.win());
    }

    /**
     * Display Lose screen
     */
    public void lose() {
        show(screen.lose());
    }
    /* End Region: State Pattern */
}
